package com.open.capacity.user.controller;

import com.netflix.discovery.converters.Auto;
import com.open.capacity.common.model.InterResume;
import com.open.capacity.common.util.PageUtil;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.user.dto.ResumeDto;
import com.open.capacity.user.model.FileInfo;
import com.open.capacity.user.service.FeignService;
import com.open.capacity.user.service.InterResumeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@Api(tags = "InterResume API")
public class InterResumeController {

    @Autowired
    private InterResumeService interResumeService;


    @ApiOperation("添加发送简历记录")
    @PutMapping("/interResume")
    public Result saveInterResume(@RequestBody InterResume interResume) {
        int save = interResumeService.save(interResume);
        return Result.succeed(save == 1 ? "保存成功!" : "保存失败");
    }

    @DeleteMapping("/interResume/{id}")
    @ApiOperation("删除简历发送记录")
    public Result deleteInterResume(@PathVariable("id") Long id) {
        int delete = interResumeService.delete(id);
        return Result.succeed(delete == 1 ? "删除成功!" : "删除失败");
    }

    @GetMapping("/interResume")
    @ApiOperation("查询简历记录")
    public PageResult getList(@RequestParam Map<String, Object> params) {
        PageUtil.pageParamConver(params,true);
        PageResult<InterResume> list = interResumeService.findList(params);
        return list;
    }

    @GetMapping("/interResume/addresser")
    @ApiOperation("根据发送人查询简历发送记录")
    public PageResult getListAddress(@RequestParam Map<String, Object> params) {
        Object addresserId = params.get("addresserId");
        Assert.notNull(addresserId, "发送方ID不能为空");
//        String addresser =addresserId.toString();
        List<ResumeDto> resumesByAdresser = interResumeService.findResumesByAdresser(params);
        return PageResult.<ResumeDto>builder().data(resumesByAdresser).code(200).count((long) resumesByAdresser.size()).build();
    }

    @GetMapping("/interResume/recipitien")
    @ApiOperation("根据收件人查询简历发送记录")
    public PageResult getListRecipitien(@RequestParam Map<String, Object> params) {
        Object recipitienId = params.get("recipitienId");
        Assert.notNull(recipitienId, "发送方ID不能为空");
//        String recipitien =recipitienId.toString();
        PageUtil.pageParamConver(params,true);
        List<ResumeDto> resumesByAdresser = interResumeService.findResumesByRecipitien(params);
        return PageResult.<ResumeDto>builder().data(resumesByAdresser).code(200).count((long) resumesByAdresser.size()).build();
    }
}
